home *** CD-ROM | disk | FTP | other *** search
/ Champak 140 / (Vol 140) Sep 19 2011.iso / Games / world-wars.swf / scripts / __Packages / classes / ww_interface / Fightbox.as < prev    next >
Text File  |  2011-09-19  |  8KB  |  268 lines

  1. class classes.ww_interface.Fightbox extends MovieClip
  2. {
  3.    function Fightbox()
  4.    {
  5.       super();
  6.       this.EXPLOSION_MC = this._parent._parent.EXPLOSION_MC;
  7.       this.UNITS_MC = this._parent._parent.UNITS_MC;
  8.       var root = this;
  9.       this.SKIP_MODE = false;
  10.       this._visible = false;
  11.       var _loc4_ = 1;
  12.       while(_loc4_ <= 8)
  13.       {
  14.          this["d" + _loc4_]._visible = false;
  15.          _loc4_ = _loc4_ + 1;
  16.       }
  17.       this.SKIP.onRelease = function()
  18.       {
  19.          _global.SOUNDS.playSound("Click- g┼éo┼¢niejszy.wav");
  20.          root.SKIP_MODE = true;
  21.          root._visible = false;
  22.          root.ultraSkip();
  23.       };
  24.    }
  25.    function registerGame(g)
  26.    {
  27.       this.GAME_CLASS = g;
  28.    }
  29.    function fight(A, B)
  30.    {
  31.       if(!this.SKIP_MODE)
  32.       {
  33.          this.LAST_FIGHT = getTimer();
  34.          this.resetDieces();
  35.          this._visible = true;
  36.          this.military1._visible = this.military2._visible = true;
  37.          this.explosion1.gotoAndStop(1);
  38.          this.explosion2.gotoAndStop(1);
  39.          this.military1.un.text = A.unitsNO;
  40.          this.military2.un.text = B.unitsNO;
  41.          this.military1.army_ico.gotoAndStop(A.army);
  42.          this.military1.army_ico.filters = [];
  43.          this.military1.army_ico.units.gotoAndStop(A.unitsNO);
  44.          this.military1.flag.gotoAndStop(A.player);
  45.          this.military2.army_ico.gotoAndStop(B.army);
  46.          this.military2.army_ico.filters = [];
  47.          this.military2.army_ico.units.gotoAndStop(B.unitsNO);
  48.          this.military2.flag.gotoAndStop(B.player);
  49.          this.ter1.gotoAndStop(A.player);
  50.          this.ter2.gotoAndStop(B.player);
  51.          var _loc8_ = 0;
  52.          var _loc7_ = 0;
  53.          this.WINNER = undefined;
  54.          var _loc5_ = 0;
  55.          while(_loc5_ < A.unitsNO)
  56.          {
  57.             var _loc6_ = this.random2(5) + 1;
  58.             _loc8_ += _loc6_;
  59.             _loc5_ = _loc5_ + 1;
  60.          }
  61.          _loc5_ = 0;
  62.          while(_loc5_ < B.unitsNO)
  63.          {
  64.             _loc6_ = this.random2(5) + 1;
  65.             _loc7_ += _loc6_;
  66.             _loc5_ = _loc5_ + 1;
  67.          }
  68.          if(_loc8_ > _loc7_)
  69.          {
  70.             this.winTemp = A;
  71.             this.winNO = 1;
  72.          }
  73.          else
  74.          {
  75.             this.winTemp = B;
  76.             this.winNO = 2;
  77.          }
  78.          this.setUltraSkip(_loc8_,_loc7_,A,B);
  79.          this.ran1.setTo(_loc8_);
  80.          this.ran2.setTo(_loc7_);
  81.          _global.SOUNDS.playSound("ko┼¢ci.wav");
  82.          this.onEnterFrame = mx.utils.Delegate.create(this,this.fightFinished);
  83.          this.dieces_limit = A.unitsNO + B.unitsNO;
  84.          this.dieces_no = 0;
  85.          this.rubbish = new Array();
  86.          this.throwDices(A.player,A.unitsNO,1);
  87.          this.throwDices(B.player,B.unitsNO,2);
  88.       }
  89.       else
  90.       {
  91.          _loc8_ = 0;
  92.          _loc7_ = 0;
  93.          this.WINNER = undefined;
  94.          _loc5_ = 0;
  95.          while(_loc5_ < A.unitsNO)
  96.          {
  97.             _loc6_ = this.random2(5) + 1;
  98.             _loc8_ += _loc6_;
  99.             _loc5_ = _loc5_ + 1;
  100.          }
  101.          _loc5_ = 0;
  102.          while(_loc5_ < B.unitsNO)
  103.          {
  104.             _loc6_ = this.random2(5) + 1;
  105.             _loc7_ += _loc6_;
  106.             _loc5_ = _loc5_ + 1;
  107.          }
  108.          if(_loc8_ > _loc7_)
  109.          {
  110.             var _loc9_ = this;
  111.             this.EXPLOSION_MC._x = this.UNITS_MC._x + B.unitsMC._x;
  112.             this.EXPLOSION_MC._y = this.UNITS_MC._y + B.unitsMC._y;
  113.             this.EXPLOSION_MC.gotoAndPlay(2);
  114.             this.winTemp = A;
  115.             this.EXPLOSION_MC.onEnterFrame = mx.utils.Delegate.create(this,this.fightFinished2);
  116.          }
  117.          else
  118.          {
  119.             this.EXPLOSION_MC._x = this.UNITS_MC._x + A.unitsMC._x;
  120.             this.EXPLOSION_MC._y = this.UNITS_MC._y + A.unitsMC._y;
  121.             this.EXPLOSION_MC.gotoAndPlay(2);
  122.             this.winTemp = B;
  123.             this.EXPLOSION_MC.onEnterFrame = mx.utils.Delegate.create(this,this.fightFinished2);
  124.          }
  125.       }
  126.    }
  127.    function setUltraSkip(pow1, pow2, A, B)
  128.    {
  129.       this.ultraSkipA = A;
  130.       this.ultraSkipB = B;
  131.       this.ultraSkipP1 = pow1;
  132.       this.ultraSkipP2 = pow2;
  133.    }
  134.    function ultraSkip()
  135.    {
  136.       delete this.onEnterFrame;
  137.       if(this.ultraSkipP1 > this.ultraSkipP2)
  138.       {
  139.          var _loc2_ = this;
  140.          this.EXPLOSION_MC._x = this.UNITS_MC._x + this.ultraSkipB.unitsMC._x;
  141.          this.EXPLOSION_MC._y = this.UNITS_MC._y + this.ultraSkipB.unitsMC._y;
  142.          this.EXPLOSION_MC.gotoAndPlay(2);
  143.          this.winTemp = this.ultraSkipA;
  144.          this.EXPLOSION_MC.onEnterFrame = mx.utils.Delegate.create(this,this.fightFinished2);
  145.       }
  146.       else
  147.       {
  148.          this.EXPLOSION_MC._x = this.UNITS_MC._x + this.ultraSkipA.unitsMC._x;
  149.          this.EXPLOSION_MC._y = this.UNITS_MC._y + this.ultraSkipA.unitsMC._y;
  150.          this.EXPLOSION_MC.gotoAndPlay(2);
  151.          this.winTemp = this.ultraSkipB;
  152.          this.EXPLOSION_MC.onEnterFrame = mx.utils.Delegate.create(this,this.fightFinished2);
  153.       }
  154.    }
  155.    function initCountdowns()
  156.    {
  157.       this.ran1.countTo();
  158.       this.ran2.countTo();
  159.    }
  160.    function fightFinished()
  161.    {
  162.       if(this.SKIP_MODE == false)
  163.       {
  164.          if(this.ran1.finished() && this.ran2.finished() && this.explosion1._currentframe == 1 && this.explosion2._currentframe == 1)
  165.          {
  166.             if(this.winNO == 1)
  167.             {
  168.                this.explosion2.gotoAndPlay(2);
  169.             }
  170.             else
  171.             {
  172.                this.explosion1.gotoAndPlay(2);
  173.             }
  174.          }
  175.          if(this.explosion1._currentframe == 7)
  176.          {
  177.             this.military1._visible = false;
  178.          }
  179.          if(this.explosion2._currentframe == 7)
  180.          {
  181.             this.military2._visible = false;
  182.          }
  183.          if(this.explosion1._currentframe == this.explosion1._totalframes || this.explosion2._currentframe == this.explosion2._totalframes)
  184.          {
  185.             this.WINNER = this.winTemp;
  186.             this.GAME_CLASS.fightFinished();
  187.             this._visible = false;
  188.             delete this.onEnterFrame;
  189.          }
  190.       }
  191.    }
  192.    function fightFinished2()
  193.    {
  194.       if(this.EXPLOSION_MC._currentframe == 7)
  195.       {
  196.          this.WINNER = this.winTemp;
  197.          this.GAME_CLASS.fightFinished();
  198.       }
  199.       if(this.EXPLOSION_MC._currentframe == this.EXPLOSION_MC._totalframes)
  200.       {
  201.          delete this.EXPLOSION_MC.onEnterFrame;
  202.       }
  203.    }
  204.    function random2(z)
  205.    {
  206.       return Math.round(Math.random() * z);
  207.    }
  208.    function throwDices(player, units, terr)
  209.    {
  210.       var root = this;
  211.       var i = 0;
  212.       while(i < units)
  213.       {
  214.          var _loc2_ = this["d" + player].duplicateMovieClip("dice" + player + "_" + i,terr * 10 + i);
  215.          this.rubbish.push(_loc2_);
  216.          _loc2_._x = this["gen" + terr]._x;
  217.          _loc2_._xscale = _loc2_._yscale = 70;
  218.          if(terr == 1)
  219.          {
  220.             _loc2_.docX = _loc2_._x + 15;
  221.          }
  222.          if(terr == 2)
  223.          {
  224.             _loc2_.docX = _loc2_._x - 15 - _loc2_._width;
  225.          }
  226.          _loc2_._y = this["gen" + terr]._y + i * 25;
  227.          _loc2_.i = (i + 2) / 2;
  228.          _loc2_.onEnterFrame = function()
  229.          {
  230.             this._x += (this.docX - this._x) / this.i;
  231.             if(Math.abs(this._x - this.docX) < 1)
  232.             {
  233.                root.dieces_no = root.dieces_no + 1;
  234.                if(root.dieces_no == root.dieces_limit)
  235.                {
  236.                   root.initCountdowns();
  237.                }
  238.                this._x = this.docX;
  239.                delete this.onEnterFrame;
  240.             }
  241.          };
  242.          i++;
  243.       }
  244.    }
  245.    function resetWinner()
  246.    {
  247.       this.WINNER = undefined;
  248.    }
  249.    function resetSkipMode()
  250.    {
  251.       this.SKIP._visible = true;
  252.       this.SKIP_MODE = false;
  253.    }
  254.    function resetDieces()
  255.    {
  256.       var _loc2_ = 0;
  257.       while(_loc2_ < this.rubbish.length)
  258.       {
  259.          this.rubbish[_loc2_].removeMovieClip();
  260.          _loc2_ = _loc2_ + 1;
  261.       }
  262.    }
  263.    function kill()
  264.    {
  265.       delete this.EXPLOSION_MC.onEnterFrame;
  266.    }
  267. }
  268.